﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Notifications;
using SampleApp.MvcBackend.Data.Model;

namespace SampleApp.MvcBackend.Messaging.Handlers
{
	public class CustomerCreatedHandler: Topics.Radical.Messaging.AbstractMessageHandler<CustomerCreated>
	{
		public CustomerCreatedHandler()
		{
			
		}

		public override void Handle( object sender, CustomerCreated message )
		{
			var cn = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessSecretWithFullAccess( "NAMESPACE", "FULL ACCESS SECRET" );
			var hubClient = NotificationHubClient.CreateClientFromConnectionString( cn, "sampleapp" );
			hubClient.SendTemplateNotification( new Dictionary<string, string> 
			{ 
				{ "property1", "Customer created: " + message.CustomerName } 
			}, tag: "my-tag" );

			var notificationBody = WindowsNotificationXmlBuilder.CreateTileSquareText04Xml( "[Tile] Customer created: " + message.CustomerName );

			hubClient.SendWindowsNativeNotification( notificationBody.InnerXml, tag: "my-tag" );
		}
	}
}